Repository navigation
gh-159538: Fix deep chain leak in test_deeply_dotted_name - #159576
Conversation
test_deeply_dotted_name() builds a 10,000-deep chain of lazy import placeholders in a thread with a 256 KiB C stack. Freeing the chain there defers most deallocations to the trashcan, which only drains them once the stack margin recovers. With a stack that small the margin never does, so the deferred objects were leaked when the thread exited, which -R reports as a reference leak on platforms with larger frames such as PPC64LE. Clear the namespace in a cleanup, which runs on the main thread.
| """) | ||
| assert_python_ok("-c", code) | ||
|
|
||
| @support.run_with_limited_c_stack(depth=10_000, size=256 * 1024) |
There was a problem hiding this comment.
This would also work as a fix:
| @support.run_with_limited_c_stack(depth=10_000, size=512 * 1024) |
vstinner
left a comment
There was a problem hiding this comment.
LGTM. I confirm that this change fix ./python -m test -R 3:3 test_lazy_import -m test_deeply_dotted_name on PPC64LE CentOS9.
|
Merged, thanks for the fix. |
|
By the way, I confirm that the following change also fix the issue on PPC64LE CentOS9: diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py
index 31006f8..84ec28e 100644
--- a/Lib/test/test_lazy_import/__init__.py
+++ b/Lib/test/test_lazy_import/__init__.py
@@ -308,7 +308,7 @@ def test_lazy_import_type_attribute_error_message(self):
""")
assert_python_ok("-c", code)
- @support.run_with_limited_c_stack(depth=10_000, size=256 * 1024)
+ @support.run_with_limited_c_stack(depth=10_000, size=512 * 1024)
def test_deeply_dotted_name(self):
"""A long dotted name must not overflow the C stack."""
m = types.SimpleNamespace()But this change seems to be less reliable to me, since it relies on specific constants. I prefer the generic |
|
Thanks @brittanyrey for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-159609 is a backport of this pull request to the 3.15 branch. |
|
Oh, Python 3.15 is also affected, see test_lazy_import failure on PPC64LE Fedora Stable Refleaks 3.15: https://buildbot.python.org/#/builders/2087/builds/242. |
…159576) (#159609) gh-159538: Fix deep chain leak in test_deeply_dotted_name (GH-159576) test_deeply_dotted_name() builds a 10,000-deep chain of lazy import placeholders in a thread with a 256 KiB C stack. Freeing the chain there defers most deallocations to the trashcan, which only drains them once the stack margin recovers. With a stack that small the margin never does, so the deferred objects were leaked when the thread exited, which -R reports as a reference leak on platforms with larger frames such as PPC64LE. Clear the namespace in a cleanup, which runs on the main thread. (cherry picked from commit c84d4b5) Co-authored-by: Brittany Reynoso <breynoso@meta.com>
test_deeply_dotted_name()builds a 10,000-deep chain of lazy import placeholders in a thread with a 256 KiB C stack. This was causing a refleak.Address it by explicitly adding a cleanup step to clear the import chain.
test_lazy_import.test_deeply_dotted_name()leaks 19,650 references on PPC64LE CentOS9 #159538